/**
 * 
 */
package com.kingcore.pda.core.tag;

import com.kingcore.pda.core.bean.CodeStyle;
import com.kingcore.pda.core.bean.SmartCodeStyle;

/**
 * @author Zeven
 *
 */
public class CodeStyleTag {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Integer i = 1234567891;
		System.out.println( i );
	} 

	private static CodeStyle getCodeStyle(String style) {
		if ("smart".equalsIgnoreCase(style)) {  //第一支持的：smart code style
			return new SmartCodeStyle();
		} else {

		}
		return null;
	}

	public static String formatClassName(String style, String objLabel) {
		return getCodeStyle(style).formatClassName(objLabel);
	}



	public static String formatObjectName(String style, String objLabel) {
		return getCodeStyle(style).formatObjectName(objLabel);
	}

	public static String convertType(String colType) {
		if (colType==null) {
			return "";
		}
		colType = colType.toLowerCase();
		if (colType.indexOf("char")>-1) {  //char,varchar,varchar2
			return "String";
			
		} else if (colType.indexOf("number")>-1 || colType.indexOf("int")>-1) {  //number,number(5),number(5.2),int,int(11)
			if (colType.indexOf(",")>-1) {
				return "Float";
				
			} else if ( colType.indexOf("(")>-1 ){  // if (type.indexOf("number")>-1) 
				String length = colType.substring( colType.indexOf("(")+1, colType.indexOf(")") );
				if( Integer.parseInt(length)> 10 )
					return "Long";
				else
					return "Integer";
				
			} else {  // if (type.indexOf("number")>-1) 
				
				return "Integer";
				
			}
			
		} else if (colType.indexOf("date")>-1) {
			return "Date";
			
		} else {
			return "String";
		}
	} 
	

	public static String convertTypeSimplified(String colType) {
		if (colType==null) {
			return "";
		}
		colType = colType.toLowerCase();
		if (colType.indexOf("char")>-1) {
			return "String";
			
		} else if (colType.indexOf("number")>-1 || colType.indexOf("int")>-1) {  //number,number(5),number(5.2),int,int(11)
			if (colType.indexOf(",")>-1) {
				return "Float";   //Float is 32-bit,Double is 64-bit.
				
			} else if ( colType.indexOf("(")>-1 ){  // if (type.indexOf("number")>-1) 
				String length = colType.substring( colType.indexOf("(")+1, colType.indexOf(")") );
				if( Integer.parseInt(length)> 10 )
					return "Long";
				else
					return "Integer";
				
			} else { // if (columnType.indexOf("number")>-1) 
				//Int相当于Oracle的number(22),存储总长度为22的整数
				return "Int";    //Int is 32bit,Long is 64bit.				
			}
			
		} else if (colType.indexOf("date")>-1) {
			return "Date";
			
		} else {
			return "String";
		}
	} 

	/**
	 * 根据数据库类型，返回页面检查的正则表达式
	 * @param colType
	 * @return
	 */
	public static String type2regular(String colType) {
		if (colType==null) {
			return "";
		}
		colType = colType.toLowerCase();
		if (colType.indexOf("char")>-1) {  //char,varchar,varchar2
			return "";
			
		} else if (colType.indexOf("number")>-1 || colType.indexOf("int")>-1) {  //number,number(5),number(5.2),int,int(11)
			if (colType.indexOf(",")>-1) {
				return "^[0-9]*$";//"Float";
				
			} else if ( colType.indexOf("(")>-1 ){  // if (type.indexOf("number")>-1) 
				String length = colType.substring( colType.indexOf("(")+1, colType.indexOf(")") );
				if( Integer.parseInt(length)> 10 )
					return "^[0-9]*$";//"Long";
				else
					return "^[0-9]*$";//"Integer";
				
			} else {  // if (type.indexOf("number")>-1) 
				
				return "^[0-9]*$";//"Integer";
				
			}
			
		} else if (colType.indexOf("date")>-1) {
			return "";
			
		} else {
			return "";
		}
	}
	
	//首字母变为小写
	public static String initialToLowerCase(String str) {
		if (str==null || str.trim().equals("")) {
			return str;
		}
		return str.substring(0, 1).toLowerCase() + str.substring(1);
	}

	//首字母变为大写
	public static String initialToUpperCase(String str) {
		if (str==null || str.trim().equals("")) {
			return str;
		}
		return str.substring(0, 1).toUpperCase() + str.substring(1);
	}
	
}
